<?php


namespace Yeepay\Yop\Sdk\Service\Sys;


use PHPUnit\Framework\TestCase;
use Yeepay\Yop\Sdk\Config\AppSdkConfig;
use Yeepay\Yop\Sdk\Exception\YopClientException;
use Yeepay\Yop\Sdk\Service\Sys\Model as Model;

class SysClientTest extends TestCase
{

    private static $client;

    public static function setUpBeforeClass()
    {
        // 常用以下两种方式构造client，根据自身情况选择其一
        // 1. 基于本地配置文件方式：支持绝对路径、相对路径(相对于根目录)，适用于将文件打包到项目中，一起部署
        $sdkConfigFile = "yop_sdk_config_default.json";
        self::$client = SysClientBuilder::builder($sdkConfigFile)->build();

        // 2. 基于json串方式：适用于自定义配置来源，从其他存储加载(比如说数据库、配置中心等)
        //$sdkConfigJson = '{"app_key":"app_xxx","server_root":"https://openapi.yeepay.com/yop-center","yos_server_root":"https://yos.yeepay.com/yop-center","yop_public_key":[{"store_type":"string","cert_type":"RSA2048","value":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6p0XWjscY+gsyqKRhw9MeLsEmhFdBRhT2emOck/F1Omw38ZWhJxh9kDfs5HzFJMrVozgU+SJFDONxs8UB0wMILKRmqfLcfClG9MyCNuJkkfm0HFQv1hRGdOvZPXj3Bckuwa7FrEXBRYUhK7vJ40afumspthmse6bs6mZxNn/mALZ2X07uznOrrc2rk41Y2HftduxZw6T4EmtWuN2x4CZ8gwSyPAW5ZzZJLQ6tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB"}],"isv_private_key":[{"store_type":"string","cert_type":"RSA2048","value":"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCf0qRvP2OJQEONEHiO5Jh2tbGo6pA3Wh7cINgpKZHLHIygZHhB4sU/2JxHqbraRsuBzC2aeWCTrXJVKjQS91vn0JHJd4BonK4ryqTRWULQkP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KCCZQ9VLaU1ur2+I/erAS+QmIH3MKpmJAoGAP15kpYMr/tE7ENgdH64tFAHp0uWa1kuRrx6JtrnEXXerGlgIeOgT/2fRrxZ0LK7sH9UMF5qRn+MLmIUoJYvA89iWBPrpdNDc9douO1XBu62xXxpUnRy9vQnwKpN4n/pmLa67PwXPbwFna2spQ/z1y1tj0S/yND9SB1qhXGBkhy0CgYBhJf0SZ9PWaasOxAsDgFsj3mSjfvoTqclRDKo1d0KFyOIKOkK3hS8ZaHA/dcR024ydc6b0mU+pyrm2/k+JuX4dHO1M9wshS1YAXytj5RCs+43ghJrbDeNxrNK4VesJPpyK0kEGHSLbMgHnSVZ4/jAgdoKEhz1cHbZorQ92XgDzBw=="}],"encrypt_key":"AWXI5fZGXmTFVHfjyzBMMrrk1IF9dCqGJt3JIZrKY90=","http_client":{"connect_timeout":3000,"read_timeout":30000,"max_conn_total":200,"max_conn_per_route":100}}';
        //self::$client = SysClientBuilder::builder(new AppSdkConfig(\GuzzleHttp\json_decode($sdkConfigJson, true)))->build();
    }

    /**
     * 子商户入网资质文件上传(/yos/v1.0/sys/merchant/qual/upload)
     *
     * @test
     */
    public function merchantQualUploadTest()
    {
        $request = new Model\MerchantQualUploadRequest();

        $request->setMerQual(fopen("/path/to/file", "r"));
        try{
            $response = self::$client->merchantQualUpload($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->merchantQualUpload: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器-分账退回(/rest/v1.0/sys/trade/divideback)
     *
     * @test
     */
    public function tradeDividebackTest()
    {
        $request = new Model\TradeDividebackRequest();

        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setDivideBackRequestId("divideBackRequestId_example");
        $request->setDivideBackDetail("divideBackDetail_example");
        $request->setNotifyUrl("notifyUrl_example");
        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setHmac("hmac_example");
        try{
            $response = self::$client->tradeDivideback($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->tradeDivideback: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——分账查询(/rest/v1.0/sys/trade/dividequery)
     *
     * @test
     */
    public function tradeDividequeryTest()
    {
        $request = new Model\TradeDividequeryRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setHmac("hmac_example");
        try{
            $response = self::$client->tradeDividequery($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->tradeDividequery: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——资金全额确认(/rest/v1.0/sys/trade/fullsettle)
     *
     * @test
     */
    public function tradeFullsettleTest()
    {
        $request = new Model\TradeFullsettleRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setHmac("hmac_example");
        try{
            $response = self::$client->tradeFullsettle($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->tradeFullsettle: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——创建订单(/rest/v1.0/sys/trade/order)
     *
     * @test
     */
    public function tradeOrderTest()
    {
        $request = new Model\TradeOrderRequest();

        $request->setParentMerchantNo("10012426723");
        $request->setMerchantNo("10012426723");
        $request->setOrderId("merchant12345");
        $request->setOrderAmount("88.88");
        $request->setTimeoutExpress(30);
        $request->setTimeoutExpressType("timeoutExpressType_example");
        $request->setRequestDate("2017-12-12 13:23:45");
        $request->setRedirectUrl("http://www.merc hant.sscom:8080/ uc/payCallback?u 8ChannelID=10");
        $request->setNotifyUrl("http://payment.m erchant.com:8080 /uc/payCallback? u8ChannelID=8");
        $request->setAssureType("REALTIME");
        $request->setAssurePeriod("assurePeriod_example");
        $request->setGoodsParamExt("{“goodsName” : “abc 商品名 称” ,” goodsDes c” : ” 商品描 述” }");
        $request->setPaymentParamExt("paymentParamExt_example");
        $request->setIndustryParamExt("industryParamExt_example");
        $request->setRiskParamExt("riskParamExt_example");
        $request->setMemo("memo_example");
        $request->setFundProcessType("fundProcessType_example");
        $request->setHmac("hmac_example");
        $request->setDivideDetail("divideDetail_example");
        $request->setCsUrl("csUrl_example");
        $request->setDivideNotifyUrl("divideNotifyUrl_example");
        $request->setTimeoutNotifyUrl("timeoutNotifyUrl_example");
        $request->setSiSubsidyMerchantAmout("siSubsidyMerchantAmout_example");
        $request->setQueryParamsExt("queryParamsExt_example");
        try{
            $response = self::$client->tradeOrder($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->tradeOrder: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——查询订单(/rest/v1.0/sys/trade/orderquery)
     *
     * @test
     */
    public function tradeOrderqueryTest()
    {
        $request = new Model\TradeOrderqueryRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setHmac("hmac_example");
        try{
            $response = self::$client->tradeOrderquery($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->tradeOrderquery: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——退款请求(/rest/v1.0/sys/trade/refund)
     *
     * @test
     */
    public function tradeRefundTest()
    {
        $request = new Model\TradeRefundRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setRefundRequestId("refundRequestId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setRefundAmount("refundAmount_example");
        $request->setAccountDivided("accountDivided_example");
        $request->setDescription("description_example");
        $request->setMemo("memo_example");
        $request->setNotifyUrl("notifyUrl_example");
        $request->setHmac("hmac_example");
        $request->setMerchantSideMarketingRefundDetails("merchantSideMarketingRefundDetails_example");
        $request->setRefundAccountType("refundAccountType_example");
        try{
            $response = self::$client->tradeRefund($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->tradeRefund: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——退款查询(/rest/v1.0/sys/trade/refundquery)
     *
     * @test
     */
    public function tradeRefundqueryTest()
    {
        $request = new Model\TradeRefundqueryRequest();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setRefundRequestId("refundRequestId_example");
        $request->setUniqueRefundNo("uniqueRefundNo_example");
        $request->setHmac("hmac_example");
        try{
            $response = self::$client->tradeRefundquery($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->tradeRefundquery: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器-分账退回(/rest/v1.0/sys/trade/divideback)
     *
     * @test
     */
    public function trade_divideback_v1_0Test()
    {
        $request = new Model\TradeDividebackV10Request();

        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setDivideBackRequestId("divideBackRequestId_example");
        $request->setDivideBackDetail("divideBackDetail_example");
        $request->setNotifyUrl("notifyUrl_example");
        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setHmac("hmac_example");
        try{
            $response = self::$client->trade_divideback_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->trade_divideback_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——分账查询(/rest/v1.0/sys/trade/dividequery)
     *
     * @test
     */
    public function trade_dividequery_v1_0Test()
    {
        $request = new Model\TradeDividequeryV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setDivideRequestId("divideRequestId_example");
        $request->setHmac("hmac_example");
        try{
            $response = self::$client->trade_dividequery_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->trade_dividequery_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——资金全额确认(/rest/v1.0/sys/trade/fullsettle)
     *
     * @test
     */
    public function trade_fullsettle_v1_0Test()
    {
        $request = new Model\TradeFullsettleV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setHmac("hmac_example");
        try{
            $response = self::$client->trade_fullsettle_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->trade_fullsettle_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——查询订单(/rest/v1.0/sys/trade/orderquery)
     *
     * @test
     */
    public function trade_orderquery_v1_0Test()
    {
        $request = new Model\TradeOrderqueryV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setHmac("hmac_example");
        try{
            $response = self::$client->trade_orderquery_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->trade_orderquery_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——退款请求(/rest/v1.0/sys/trade/refund)
     *
     * @test
     */
    public function trade_refund_v1_0Test()
    {
        $request = new Model\TradeRefundV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setRefundRequestId("refundRequestId_example");
        $request->setUniqueOrderNo("uniqueOrderNo_example");
        $request->setRefundAmount("refundAmount_example");
        $request->setAccountDivided("accountDivided_example");
        $request->setDescription("description_example");
        $request->setMemo("memo_example");
        $request->setNotifyUrl("notifyUrl_example");
        $request->setHmac("hmac_example");
        $request->setMerchantSideMarketingRefundDetails("merchantSideMarketingRefundDetails_example");
        $request->setRefundAccountType("refundAccountType_example");
        try{
            $response = self::$client->trade_refund_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->trade_refund_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
    /**
     * 订单处理器——退款查询(/rest/v1.0/sys/trade/refundquery)
     *
     * @test
     */
    public function trade_refundquery_v1_0Test()
    {
        $request = new Model\TradeRefundqueryV10Request();

        $request->setParentMerchantNo("parentMerchantNo_example");
        $request->setMerchantNo("merchantNo_example");
        $request->setOrderId("orderId_example");
        $request->setRefundRequestId("refundRequestId_example");
        $request->setUniqueRefundNo("uniqueRefundNo_example");
        $request->setHmac("hmac_example");
        try{
            $response = self::$client->trade_refundquery_v1_0($request);
            print_r($response->getResult());
        }catch (\Exception $e) {
            echo 'Exception when calling SysClient->trade_refundquery_v1_0: ', $e->getMessage(), PHP_EOL;
        }
    }
}
